<HTML><HEAD><TITLE>new_socket_server(?Socket, ?Address, +Queue)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Stream I/O</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>new_socket_server(?Socket, ?Address, +Queue)</H1>
Opens a new IP socket server stream with a maximum of Queue connections.
<DL>
<DT><EM>Socket</EM></DT>
<DD>Socket server name (atom or variable)
</DD>
<DT><EM>Address</EM></DT>
<DD>Address for socket connection (Host/Port or variable)
</DD>
<DT><EM>Queue</EM></DT>
<DD>Number of connections allowed (integer)
</DD>
</DL>
<H2>Description</H2>
   <P> Opens a new IP socket server stream Socket at host Host and port number
   Port. It is allowed a maximum of Queue connection requests.

</P><P>
   This predicate combines the calls to socket/3, bind/2, listen/2 to
   create a socket server. After creation of the socket server, accept/2
   can be called to accept client socket stream connections. Socket is
   closed if either the bind/2 or listen/2 calls throws an exception and 
   thus a server socket cannot be made.


<H3>Modes and Determinism</H3><UL>
<LI>new_socket_server(-, ?, +) is det
<LI>new_socket_server(+, ?, +) is det
</UL>
<H2>Examples</H2>
<PRE>

% Set up a socket server and accept a socket connection. The following will
% print the Port number used for the server, and waits for a client connection
[eclipse 26]: new_socket_server(Server, localhost/Port, 1), writeln(Port), accept(Server, _, Socket).
27694
....

% On a different ECLiPSe process running on the same machine (as localhost
% is used for the host name)

socket(internet, stream, Client), connect(Client, localhost/27694).

Client = 9
Yes (0.00s cpu)
[eclipse 3]: 
...

% On the original ECLiPSe process, the accept/3 call will now return
[eclipse 26]: new_socket_server(Server, localhost/Port, 1), writeln(Port), accept(Server, _, Socket).
27694

Port = 27694
Server = 9
Socket = 11
Yes (0.00s cpu)
% The Server can now be closed while the socket stream remains connected
[eclipse 27]: close(9).

</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/iostream/accept-3.html">accept / 3</A>, <A HREF="../../kernel/iostream/socket-3.html">socket / 3</A>, <A HREF="../../kernel/iostream/bind-2.html">bind / 2</A>, <A HREF="../../kernel/iostream/listen-2.html">listen / 2</A>
</BODY></HTML>
